#!/bin/bash

params=$@

[ $# -eq 0 ] && { echo "$0: Missing params" ; echo "Usage: $0 [all] pb-gateway pb-oss ..." ; exit 1 ; }

fullpath=`pwd -P .`
cd $fullpath


echo "-----------------------------------------"
echo "Ready to git pull in projects: $params"
echo "-----------------------------------------"

branch=`git rev-parse --abbrev-ref HEAD`
git pull origin $branch
        
for p in $params ; do
  if [ $p == "all" ] ; then
    for f in */ ; do
      if [ -d "$f" ] ; then
      	echo "------------------------< $f >"
        cd $f
        branch=`git rev-parse --abbrev-ref HEAD`
        git pull origin $branch
        cd $fullpath ;
      fi ;
    done ;
  elif [ -d "$p" ] ; then 
    cd $p 
    branch=`git rev-parse --abbrev-ref HEAD`
    git pull origin $branch
    cd $fullpath ;
  else 
    echo "$p directory not exists!"
    exit 1 ;
  fi ;
done ;
    







